package com.ktgj.sms.api.factory;

import com.ktgj.common.core.domain.R;
import com.ktgj.sms.api.RemoteSmsTemplateService;
import com.ktgj.sms.api.domain.SmsTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 短信模板服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteSmsTemplateFallbackFactory implements FallbackFactory<RemoteSmsTemplateService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteSmsTemplateFallbackFactory.class);

    @Override
    public RemoteSmsTemplateService create(Throwable throwable)
    {
        log.error("短信模板服务调用失败:{}", throwable.getMessage());
        return new RemoteSmsTemplateService()
        {
            @Override
            public R<SmsTemplate> getTemplate(Long smsTemplateId)
            {
                return R.fail("获取短信模板失败:" + throwable.getMessage());
            }
        };
    }
}
